<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use Redis;  
use fast\Pinyin;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';
	
	 
	public function myAssertHandler($file, $line, $code, $desc = null) {  
		throw new AssertionError("Assertion failed in $file on line $line: $code");  
	}  
	// 定义一个函数，其中包含断言  
	public function calculateSum($a, $b) { 
	ini_set('assert.active', '1');  
	// 设置断言回调函数  
	ini_set('assert.callback', 'myAssertHandler');  
	// 设置断言错误报告级别  
	ini_set('assert.exception', '1');  
		// 调用函数并传入负数参数  	
		assert($a >= 0 && $b >= 0, 'Both numbers must be non-negative');  
		return $a + $b;  
	}  	
    public function index()
    {
		return $this->view->fetch();
    }
	
	public function ad(){
		$redis = new Redis();  
        $redis->connect('127.0.0.1', 6379);
		$order=array(
			"No"=>substr(uniqid(),7,4),
			"title"=>"测试队列".rand(100,999),
			"create_time"=>time()
		);
		//$res=$redis->lpush('orders',$order);
		//$ret=$redis->lrange('orders', 0, -1);
		//$red=$redis->lpop('orders');
		//var_dump($ret);
	}
	public function get_p(){
		$a=Pinyin::get('张',true);
		echo $a;
	}
	public function duan(){
	
	try {  
		$result = $this->calculateSum(-5, 10);  
		echo "Sum: $result\n";  
	} catch (AssertionError $e) {  
		echo "Caught assertion error: " . $e->getMessage() . "\n";  
	}  
	}

}
